/*   1:    */ package org.jetbrains.jps.model.serialization.library;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.JDOMUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsDummyElement;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
import org.jetbrains.jps.model.java.JpsJavaSdkType;
import org.jetbrains.jps.model.java.JpsJavaSdkTypeWrapper;
import org.jetbrains.jps.model.library.JpsLibrary;
import org.jetbrains.jps.model.library.JpsLibraryCollection;
import org.jetbrains.jps.model.library.JpsLibraryRoot;
import org.jetbrains.jps.model.library.JpsOrderRootType;
import org.jetbrains.jps.model.library.sdk.JpsSdk;
import org.jetbrains.jps.model.library.sdk.JpsSdkReference;
import org.jetbrains.jps.model.library.sdk.JpsSdkType;
import org.jetbrains.jps.model.module.JpsSdkReferencesTable;
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;

import java.io.File;
import java.util.*;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */ 
/*  30:    */ public class JpsSdkTableSerializer
/*  31:    */ {
/*  32: 46 */   private static final Logger a = Logger.getInstance(JpsSdkTableSerializer.class);
/*  33: 48 */   private static final JpsLibraryRootTypeSerializer[] b = { new JpsLibraryRootTypeSerializer("classPath", JpsOrderRootType.COMPILED, true), new JpsLibraryRootTypeSerializer("sourcePath", JpsOrderRootType.SOURCES, true) };
/*  34: 52 */   private static final JpsSdkPropertiesSerializer<JpsDummyElement> c = new JpsSdkPropertiesSerializer("JavaSDK", JpsJavaSdkType.INSTANCE)
/*  35:    */   {
/*  36:    */     @NotNull
/*  37:    */     public JpsDummyElement loadProperties(Element paramAnonymousElement)
/*  38:    */     {
/*  39: 57 */       JpsDummyElement tmp6_3 = JpsElementFactory.getInstance().createDummyElement();
/*  40: 57 */       if (tmp6_3 == null) {
/*  41: 57 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/serialization/library/JpsSdkTableSerializer$1", "loadProperties" }));
/*  42:    */       }
/*  43: 57 */       return tmp6_3;
/*  44:    */     }
/*  45:    */     
/*  46:    */     public void saveProperties(@NotNull JpsDummyElement paramAnonymousJpsDummyElement, @NotNull Element paramAnonymousElement)
/*  47:    */     {
/*  48: 62 */       if (paramAnonymousJpsDummyElement == null) {
/*  49: 62 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/serialization/library/JpsSdkTableSerializer$1", "saveProperties" }));
/*  50:    */       }
/*  51: 62 */       if (paramAnonymousElement == null) {
/*  52: 62 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/serialization/library/JpsSdkTableSerializer$1", "saveProperties" }));
/*  53:    */       }
/*  54:    */     }
/*  55:    */   };
/*  56:    */   private static final String d = "jdk";
/*  57:    */   private static final String e = "name";
/*  58:    */   private static final String f = "type";
/*  59:    */   private static final String g = "type";
/*  60:    */   private static final String h = "roots";
/*  61:    */   private static final String i = "root";
/*  62:    */   private static final String j = "version";
/*  63:    */   private static final String k = "homePath";
/*  64:    */   private static final String l = "value";
/*  65:    */   private static final String m = "composite";
/*  66:    */   private static final String n = "simple";
/*  67:    */   private static final String o = "url";
/*  68:    */   private static final String p = "additional";
/*  69:    */   
/*  70:    */   public static void loadSdks(@Nullable Element paramElement, JpsLibraryCollection paramJpsLibraryCollection)
/*  71:    */   {
/*  72: 79 */     for (Element localElement : JDOMUtil.getChildren(paramElement, "jdk")) {
/*  73: 80 */       paramJpsLibraryCollection.addLibrary(a(localElement));
/*  74:    */     }
/*  75:    */   }
/*  76:    */   
/*  77:    */   public static void saveSdks(JpsLibraryCollection paramJpsLibraryCollection, Element paramElement)
/*  78:    */   {
/*  79: 85 */     for (JpsLibrary localJpsLibrary : paramJpsLibraryCollection.getLibraries())
/*  80:    */     {
/*  81: 86 */       JpsElement localJpsElement = localJpsLibrary.getProperties();
/*  82: 87 */       if ((localJpsElement instanceof JpsSdk))
/*  83:    */       {
/*  84: 88 */         Element localElement = new Element("jdk");
/*  85: 89 */         a((JpsSdk)localJpsElement, localElement);
/*  86: 90 */         paramElement.addContent(localElement);
/*  87:    */       }
/*  88:    */     }
/*  89:    */   }
/*  90:    */   
/*  91:    */   private static JpsLibrary a(Element paramElement)
/*  92:    */   {
/*  93: 96 */     String str1 = a(paramElement, "name");
/*  94: 97 */     String str2 = a(paramElement, "type");
/*  95: 98 */     a.debug("Loading " + str2 + " SDK '" + str1 + "'");
/*  96: 99 */     JpsSdkPropertiesSerializer localJpsSdkPropertiesSerializer = getSdkPropertiesSerializer(str2);
/*  97:100 */     JpsLibrary localJpsLibrary = a(str1, localJpsSdkPropertiesSerializer, paramElement);
/*  98:101 */     Element localElement1 = paramElement.getChild("roots");
/*  99:102 */     for (Object localObject1 = JDOMUtil.getChildren(localElement1).iterator(); ((Iterator)localObject1).hasNext();)
/* 100:    */     {
/* 101:102 */       localObject2 = (Element)((Iterator)localObject1).next();
/* 102:103 */       localObject3 = a(((Element)localObject2).getName());
/* 103:104 */       if (localObject3 != null) {
/* 104:105 */         for (Element localElement2 : JDOMUtil.getChildren((Element)localObject2)) {
/* 105:106 */           a(localElement2, localJpsLibrary, ((JpsLibraryRootTypeSerializer)localObject3).getType());
/* 106:    */         }
/* 107:    */       } else {
/* 108:110 */         a.info("root type serializer not found for " + ((Element)localObject2).getName());
/* 109:    */       }
/* 110:    */     }
/* 111:    */     Object localObject2;
/* 112:    */     Object localObject3;
/* 113:113 */     if (a.isDebugEnabled())
/* 114:    */     {
/* 115:114 */       localObject1 = localJpsLibrary.getFiles(JpsOrderRootType.COMPILED);
/* 116:115 */       a.debug(str1 + " SDK classpath (" + ((List)localObject1).size() + " roots):");
/* 117:116 */       for (localObject2 = ((List)localObject1).iterator(); ((Iterator)localObject2).hasNext();)
/* 118:    */       {
/* 119:116 */         localObject3 = (File)((Iterator)localObject2).next();
/* 120:117 */         a.debug(" " + ((File)localObject3).getAbsolutePath());
/* 121:    */       }
/* 122:    */     }
/* 123:120 */     return localJpsLibrary;
/* 124:    */   }
/* 125:    */   
/* 126:    */   private static <P extends JpsElement> void a(JpsSdk<P> paramJpsSdk, Element paramElement)
/* 127:    */   {
/* 128:124 */     JpsLibrary localJpsLibrary = paramJpsSdk.getParent();
/* 129:125 */     paramElement.setAttribute("version", "2");
/* 130:126 */     a(paramElement, "name", localJpsLibrary.getName());
/* 131:127 */     JpsSdkPropertiesSerializer localJpsSdkPropertiesSerializer = getSdkPropertiesSerializer(paramJpsSdk.getSdkType());
/* 132:128 */     a(paramElement, "type", localJpsSdkPropertiesSerializer.getTypeId());
/* 133:129 */     String str = paramJpsSdk.getVersionString();
/* 134:130 */     if (str != null) {
/* 135:131 */       a(paramElement, "version", str);
/* 136:    */     }
/* 137:133 */     a(paramElement, "homePath", paramJpsSdk.getHomePath());
/* 138:    */     
/* 139:135 */     Element localElement1 = new Element("roots");
/* 140:136 */     for (Object localObject = a().iterator(); ((Iterator)localObject).hasNext();)
/* 141:    */     {
/* 142:136 */       JpsLibraryRootTypeSerializer localJpsLibraryRootTypeSerializer = (JpsLibraryRootTypeSerializer)((Iterator)localObject).next();
/* 143:137 */       Element localElement2 = new Element(localJpsLibraryRootTypeSerializer.getTypeId());
/* 144:138 */       Element localElement3 = new Element("root");
/* 145:139 */       localElement3.setAttribute("type", "composite");
/* 146:140 */       List localList = localJpsLibrary.getRoots(localJpsLibraryRootTypeSerializer.getType());
/* 147:141 */       for (JpsLibraryRoot localJpsLibraryRoot : localList) {
/* 148:142 */         localElement3.addContent(new Element("root").setAttribute("type", "simple").setAttribute("url", localJpsLibraryRoot.getUrl()));
/* 149:    */       }
/* 150:144 */       localElement2.addContent(localElement3);
/* 151:145 */       localElement1.addContent(localElement2);
/* 152:    */     }
/* 153:147 */     paramElement.addContent(localElement1);
/* 154:    */     
/* 155:149 */     localObject = new Element("additional");
/* 156:150 */     localJpsSdkPropertiesSerializer.saveProperties(paramJpsSdk.getSdkProperties(), (Element)localObject);
/* 157:151 */     paramElement.addContent((Element)localObject);
/* 158:    */   }
/* 159:    */   
/* 160:    */   private static void a(Element paramElement, String paramString1, String paramString2)
/* 161:    */   {
/* 162:155 */     paramElement.addContent(new Element(paramString1).setAttribute("value", paramString2));
/* 163:    */   }
/* 164:    */   
/* 165:    */   private static void a(Element paramElement, JpsLibrary paramJpsLibrary, JpsOrderRootType paramJpsOrderRootType)
/* 166:    */   {
/* 167:159 */     String str = paramElement.getAttributeValue("type");
/* 168:160 */     if (str.equals("composite")) {
/* 169:161 */       for (Element localElement : JDOMUtil.getChildren(paramElement)) {
/* 170:162 */         a(localElement, paramJpsLibrary, paramJpsOrderRootType);
/* 171:    */       }
/* 172:165 */     } else if (str.equals("simple")) {
/* 173:166 */       paramJpsLibrary.addRoot(paramElement.getAttributeValue("url"), paramJpsOrderRootType);
/* 174:    */     }
/* 175:    */   }
/* 176:    */   
/* 177:    */   @Nullable
/* 178:    */   private static JpsLibraryRootTypeSerializer a(String paramString)
/* 179:    */   {
/* 180:    */     JpsLibraryRootTypeSerializer localJpsLibraryRootTypeSerializer;
/* 181:172 */     for (localJpsLibraryRootTypeSerializer : b) {
/* 182:173 */       if (localJpsLibraryRootTypeSerializer.getTypeId().equals(paramString)) {
/* 183:174 */         return localJpsLibraryRootTypeSerializer;
/* 184:    */       }
/* 185:    */     }
/* 186:177 */     for (??? = JpsModelSerializerExtension.getExtensions().iterator(); ((Iterator)???).hasNext();)
/* 187:    */     {
/* 188:177 */       JpsModelSerializerExtension localJpsModelSerializerExtension = (JpsModelSerializerExtension)((Iterator)???).next();
/* 189:178 */       for (localIterator = localJpsModelSerializerExtension.getSdkRootTypeSerializers().iterator(); localIterator.hasNext();)
/* 190:    */       {
/* 191:178 */         localJpsLibraryRootTypeSerializer = (JpsLibraryRootTypeSerializer)localIterator.next();
/* 192:179 */         if (localJpsLibraryRootTypeSerializer.getTypeId().equals(paramString)) {
/* 193:180 */           return localJpsLibraryRootTypeSerializer;
/* 194:    */         }
/* 195:    */       }
/* 196:    */     }
/* 197:    */     Iterator localIterator;
/* 198:184 */     return null;
/* 199:    */   }
/* 200:    */   
/* 201:    */   private static List<JpsLibraryRootTypeSerializer> a()
/* 202:    */   {
/* 203:188 */     ArrayList localArrayList = new ArrayList(Arrays.asList(b));
/* 204:189 */     for (JpsModelSerializerExtension localJpsModelSerializerExtension : JpsModelSerializerExtension.getExtensions()) {
/* 205:190 */       localArrayList.addAll(localJpsModelSerializerExtension.getSdkRootTypeSerializers());
/* 206:    */     }
/* 207:192 */     Collections.sort(localArrayList);
/* 208:193 */     return localArrayList;
/* 209:    */   }
/* 210:    */   
/* 211:    */   private static <P extends JpsElement> JpsLibrary a(String paramString, JpsSdkPropertiesSerializer<P> paramJpsSdkPropertiesSerializer, Element paramElement)
/* 212:    */   {
/* 213:197 */     String str1 = a(paramElement, "version");
/* 214:198 */     String str2 = a(paramElement, "homePath");
/* 215:199 */     Element localElement = paramElement.getChild("additional");
/* 216:200 */     JpsElement localJpsElement = paramJpsSdkPropertiesSerializer.loadProperties(localElement);
/* 217:201 */     return JpsElementFactory.getInstance().createSdk(paramString, str2, str1, (JpsSdkType)paramJpsSdkPropertiesSerializer.getType(), localJpsElement);
/* 218:    */   }
/* 219:    */   
/* 220:    */   public static JpsSdkPropertiesSerializer<?> getSdkPropertiesSerializer(@Nullable String paramString)
/* 221:    */   {
/* 222:205 */     for (JpsModelSerializerExtension localJpsModelSerializerExtension : ) {
/* 223:206 */       for (JpsSdkPropertiesSerializer localJpsSdkPropertiesSerializer : localJpsModelSerializerExtension.getSdkPropertiesSerializers()) {
/* 224:207 */         if (localJpsSdkPropertiesSerializer.getTypeId().equals(paramString)) {
/* 225:208 */           return localJpsSdkPropertiesSerializer;
/* 226:    */         }
/* 227:    */       }
/* 228:    */     }
/* 229:212 */     return c;
/* 230:    */   }
/* 231:    */   
/* 232:    */   public static <P extends JpsElement> JpsSdkPropertiesSerializer<P> getSdkPropertiesSerializer(JpsSdkType<P> paramJpsSdkType)
/* 233:    */   {
/* 234:216 */     for (JpsModelSerializerExtension localJpsModelSerializerExtension : ) {
/* 235:217 */       for (JpsSdkPropertiesSerializer localJpsSdkPropertiesSerializer : localJpsModelSerializerExtension.getSdkPropertiesSerializers()) {
/* 236:218 */         if (((JpsSdkType)localJpsSdkPropertiesSerializer.getType()).equals(paramJpsSdkType)) {
/* 237:220 */           return localJpsSdkPropertiesSerializer;
/* 238:    */         }
/* 239:    */       }
/* 240:    */     }
/* 241:225 */     return c;
/* 242:    */   }
/* 243:    */   
/* 244:    */   @Nullable
/* 245:    */   private static String a(Element paramElement, String paramString)
/* 246:    */   {
/* 247:230 */     Element localElement = paramElement.getChild(paramString);
/* 248:231 */     return localElement != null ? localElement.getAttributeValue("value") : null;
/* 249:    */   }
/* 250:    */   
/* 251:    */   public static JpsSdkType<?> getSdkType(@Nullable String paramString)
/* 252:    */   {
/* 253:235 */     return (JpsSdkType)getSdkPropertiesSerializer(paramString).getType();
/* 254:    */   }
/* 255:    */   
/* 256:    */   public static JpsSdkPropertiesSerializer<?> getLoader(JpsSdkType<?> paramJpsSdkType)
/* 257:    */   {
/* 258:239 */     for (JpsModelSerializerExtension localJpsModelSerializerExtension : ) {
/* 259:240 */       for (JpsSdkPropertiesSerializer localJpsSdkPropertiesSerializer : localJpsModelSerializerExtension.getSdkPropertiesSerializers()) {
/* 260:241 */         if (((JpsSdkType)localJpsSdkPropertiesSerializer.getType()).equals(paramJpsSdkType)) {
/* 261:242 */           return localJpsSdkPropertiesSerializer;
/* 262:    */         }
/* 263:    */       }
/* 264:    */     }
/* 265:246 */     return c;
/* 266:    */   }
/* 267:    */   
/* 268:    */   public static <P extends JpsElement> void setSdkReference(JpsSdkReferencesTable paramJpsSdkReferencesTable, String paramString, JpsSdkType<P> paramJpsSdkType)
/* 269:    */   {
/* 270:250 */     JpsSdkReference localJpsSdkReference1 = JpsElementFactory.getInstance().createSdkReference(paramString, paramJpsSdkType);
/* 271:251 */     paramJpsSdkReferencesTable.setSdkReference(paramJpsSdkType, localJpsSdkReference1);
/* 272:252 */     if ((paramJpsSdkType instanceof JpsJavaSdkTypeWrapper))
/* 273:    */     {
/* 274:253 */       JpsSdkReference localJpsSdkReference2 = JpsElementFactory.getInstance().createSdkReference(paramString, paramJpsSdkType);
/* 275:254 */       paramJpsSdkReferencesTable.setSdkReference(JpsJavaSdkType.INSTANCE, JpsJavaExtensionService.getInstance().createWrappedJavaSdkReference((JpsJavaSdkTypeWrapper)paramJpsSdkType, localJpsSdkReference2));
/* 276:    */     }
/* 277:    */   }
/* 278:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.serialization.library.JpsSdkTableSerializer

 * JD-Core Version:    0.7.0.1

 */